package apis

import (
	"k8sdev/pkg/services"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	v1 "k8s.io/api/core/v1"
)

func GetNodes(c *gin.Context) {
	var (
		nodes     []string
		nodesList *[]v1.Node
		err       error
	)
	nodes = make([]string, 0, 10)
	nodesList, err = services.GetNodes()
	if err != nil {
		log.Fatal(err.Error())
		return
	}
	for _, item := range *nodesList {
		nodes = append(nodes, item.Name)
	}
	c.JSON(http.StatusOK, gin.H{
		"nodes": nodes,
	})
}
